const App = getApp()
Page({
  data: {
    currentTab: 0,
    list: [],
    page: 1,
    nomore: false,
    pageShow:true,
  },
  onLoad: function (options) {
    this.setData({
      currentTab: 0
    })
  },
  onReady: function () {

  },
  onShow: function () {
    let that = this
    that.setData({
      // currentTab: wx.getStorageSync('type'),
      list: [],
      page: 1
    })
    that.list()
  },
  async list() {
    let that = this
    await App.api.$http({
      url: 'Service/lists',
      method: 'GET',
      data: {
        service_type: that.data.currentTab||0,
        page:that.data.page
      }
    }, {}).then(res => {
      that.setData({
        pageShow:true
      })
      if (res) {
        if (that.data.page < res.data.list.last_page) {
          let hotPage = that.data.page + 1;
          that.setData({
            page: hotPage,
            nomore: true
          })
        } else {
          that.setData({
            nomore: false
          })
        }
        let lists = that.data.list.concat(res.data.list.data)
        that.setData({
          list: lists
        })
      }
    })
  },
  // tab切换
  swichNav(e) {
    let that = this
    that.setData({
      currentTab: e.target.dataset.index,
      list: []
    })
    wx.setStorageSync('type', that.data.currentTab)
    that.list()
  },

  // 点击地图导航
  toMap(e) {
    let detail=e.currentTarget.dataset.item
    wx.openLocation({
      latitude:Number(detail.latitude),
      longitude:Number(detail.longitude),
      scale: 18
    })
  },
  phone(e) {
    App.api.$makePhone(e)
  },
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.nomore) {
      this.list();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})